package com.example.testdemo.utils;

import lombok.extern.slf4j.Slf4j;
import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

import java.io.IOException;

/**
 * @description:
 * @author: hkai
 * @date: 2021/12/21 9:38 下午
 * @version: 1.0
 */
@Slf4j
public class HttpUtils {

    public static String url = "http://127.0.0.1:8080/test/t1";

    public static String getHttp() {
        OkHttpClient httpClient = new OkHttpClient();
        Request getRequest = new Request.Builder()
                .url(url)
                .get()
                .build();

        Call call = httpClient.newCall(getRequest);
        String ret = null;
        try {
            Response response = call.execute();
            ret = response.body().string();
            log.info("okHttpGet run: response:"+ ret);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return ret;
    }
}
